/**
 * Created by Administrator on 2018/6/26.
 */
/*筛选*/
$(".search").click(function () {
    var data = $("#searchform").serialize();
    window.location.href = '/admin/Message/accurateIndex?' + data;
});
/**删除***/
$("#info_delete").click(function () {
    var act = $(this).attr('id');
    var value = new Array();
    $("tbody span[class='checked'] input").each(function (a, b) {
        value[a] = 'id=' + $(this).val();
    });
    var ids = value.join('&');
    var confirm_msg = "确认删除通知吗";
    if(ids==''){
        dshow('请选择至少一条数据进行操作');
        return false;
    }
    if (confirm(confirm_msg)) {
        $.ajax({
            url: '/admin/Message/articleDel',
            type: 'POST',
            data: {ids: ids, act: act},
            dataType: 'JSON',
            cache: false,
            success: function (json) {
                dshow(json.message);
                if (json.code == 2000) {
                    var page = $("input[name='page']").val();
                    window.location.href = '/admin/Message/accurateIndex?page=' + page;
                }
            }
        });
    }
});
/*省市联动*/
$("#province").on("change",function () {
    var city = $("#province").val();
    getCity(city);
})
function getCity(city){
    $.ajax({
        url: '/admin/message/city',
        data: {city: city},
        type: 'POST',
        dataType: 'json',//返回的数据类型
        success: function (data) {
            var cityArray =  data.cityArray;
            $("#city").html("");
            var html = " <option value=''>全部</option>";
            $.each(cityArray, function (i, item) {
                html += "<option value='"+item.district_id+"'>" + item.district + "</option>";
            });
            $("#city").append(html);
        }
    })
}
/*查看详情*/
$('.details').click(function(){
    var a_id = $(this).attr('data-id');
    var page = $("input[name='page']").val();
    window.location.href = '/admin/Message/accurateDetails?a_id=' + a_id + '&page=' + page;
})
/*下架*/
$('.down').click(function () {
    var downs = $(this);
    var a_id = $(this).attr('data-id');
    $.ajax({
        url:'/admin/Message/articleDown',
        type:'post',
        data:{a_id:a_id},
        dataType:'JSON',
        success:function (res) {
            res = JSON.parse(res);
            if(res.code == 200){
                downs.html('已下架');
                dshow('操作成功');
            }
        }
    })
})

